clear*
set maxvar 11000

global date _2025_10_28
cd "/Users/atri0032/Dropbox/World Bank/Temperature, poverty, and inequality/Estimations/"

****************************************************************************************************************************************************************
********************************** Table S14: The effects of temperature on poverty and inequality by income group (using time-varying WB income classification)
****************************************************************************************************************************************************************

* FE model 
use "${date}/_data/spid_for_analysis_v2.dta", clear

	sort code year
	merge m:1 code year using "${date}/_data/income_classification.dta"
	drop if _merge==2
	drop _merge

estimates clear	
	
local controls ln_GDPppp Unempilo agri manuf popgr 
	
reghdfe poor215 temp rainfall_sum humid `controls' if inlist(income_classification,"L","LM"), absorb(geo_code2_new year) cluster(geo_code2_new) keepsingle	
	est store m1
reghdfe poor215 temp rainfall_sum humid `controls' if inlist(income_classification,"H","UM"), absorb(geo_code2_new year) cluster(geo_code2_new) keepsingle	
	est store m2
reghdfe gini temp rainfall_sum humid `controls' if inlist(income_classification,"L","LM"), absorb(geo_code2_new year) cluster(geo_code2_new) keepsingle	
	est store m3
reghdfe gini temp rainfall_sum humid `controls' if inlist(income_classification,"H","UM"), absorb(geo_code2_new year) cluster(geo_code2_new) keepsingle	
	est store m4
	
local opts ///
	cells(b(star fmt(3)) se(par fmt(3))) star(* 0.10 ** 0.05 *** 0.01) ///
	stats(N r2, fmt(0 3) ///
	label("Observations" "R-squared")) ///	
	eqlabels(none) mtitle("Poverty - low inc" "Poverty - high inc" "Gini - low inc" "Gini - high inc") ///
	collabels(,none) varlabels(temp "Temperature" rainfall_ave "Rainfall" humid "Humidity") varwidth(25) ///
	title("Table s14 - FE")
	
esttab m*, `opts' 
esttab m* using "${date}/_tables/_tab_s14_FE.csv", replace `opts' 

* LD model 
bysort 	geo_code2_new (year): egen year_min = min(year)
bysort 	geo_code2_new (year): egen year_max = max(year)

keep if year == year_min | year == year_max

bysort geo_code2_new (year): gen n = _n
bysort geo_code2_new (year): gen N = _N
	keep if N==2
	
encode geo_code2_new, gen(id_region)	
xtset id_region n
foreach v in gini theil temp poor215 poor365 poor685 rainfall_sum humid ln_GDPppp Unempilo agri manuf edupri eduter popgr tech {
	gen `v'_d = D.`v'
}
	
collapse (mean) poor215_d poor365_d poor685_d gini_d theil_d temp_d rainfall_sum_d humid_d ln_GDPppp_d Unempilo_d agri_d manuf_d popgr_d, by(geo_code2_new year income_classification)
	
estimates clear	

local controls ln_GDPppp_d Unempilo_d agri_d manuf_d popgr_d   

reg poor215_d temp_d rainfall_sum_d humid_d `controls' if inlist(income_classification,"L","LM"), cluster(geo_code2_new) 
	est store m1	
reg poor215_d temp_d rainfall_sum_d humid_d `controls' if inlist(income_classification,"H","UM"), cluster(geo_code2_new) 	
	est store m2
reg gini_d temp_d rainfall_sum_d humid_d `controls' if inlist(income_classification,"L","LM"), cluster(geo_code2_new) 
	est store m3	
reg gini_d temp_d rainfall_sum_d humid_d `controls' if inlist(income_classification,"H","UM"), cluster(geo_code2_new) 
	est store m4	
	
local opts ///
	cells(b(star fmt(3)) se(par fmt(3))) star(* 0.10 ** 0.05 *** 0.01) ///
	stats(N r2, fmt(0 3) ///
	label("Observations" "R-squared")) ///	
	eqlabels(none) mtitle("Poverty - low inc" "Poverty - high inc" "Gini - low inc" "Gini - high inc") ///
	collabels(,none) varlabels(temp "Temperature" rainfall_ave "Rainfall" humid "Humidity") varwidth(25) ///
	title("Table s14 - LD")	
	
esttab m*, `opts' 	
esttab m* using "${date}/_tables/_tab_s14_LD.csv", replace `opts' 

//==========================//	
	
// T-test: Lower income vs Higher income
* Fixed effects model
use "${date}/_data/spid_for_analysis_v2.dta", clear

encode geo_code2_new, gen(id_region)

	sort code year
	merge m:1 code year using "${date}/_data/income_classification.dta"
	drop if _merge==2
	drop _merge

qui reg poor215 temp rainfall_sum humid b2010.year b42.id_region ln_GDPppp Unempilo agri manuf popgr if inlist(income_classification,"L","LM")	
	est store low_inc
qui reg poor215 temp rainfall_sum humid b2010.year b42.id_region ln_GDPppp Unempilo agri manuf popgr if inlist(income_classification,"H","UM")
	est store high_inc
	
qui suest low_inc high_inc	
test [low_inc_mean]temp - [high_inc_mean]temp = 0

estimates clear
qui reg gini temp rainfall_sum humid b2010.year b42.id_region ln_GDPppp Unempilo agri manuf popgr if inlist(income_classification,"L","LM")
	est store low_inc
qui reg gini temp rainfall_sum humid b2010.year b42.id_region ln_GDPppp Unempilo agri manuf popgr if inlist(income_classification,"H","UM")
	est store high_inc
	
qui suest low_inc high_inc	
test [low_inc_mean]temp - [high_inc_mean]temp = 0

* LD model
use "${date}/_data/spid_for_analysis_v2.dta", clear

	sort code year
	merge m:1 code year using "${date}/_data/income_classification.dta"
	drop if _merge==2
	drop _merge

bysort 	geo_code2_new (year): egen year_min = min(year)
bysort 	geo_code2_new (year): egen year_max = max(year)

keep if year == year_min | year == year_max

bysort geo_code2_new (year): gen n = _n
bysort geo_code2_new (year): gen N = _N
	keep if N==2
	
encode geo_code2_new, gen(id_region)	
xtset id_region n
foreach v in gini theil temp poor215 poor365 poor685 rainfall_sum humid ln_GDPppp Unempilo agri manuf edupri eduter popgr tech {
	gen `v'_d = D.`v'
}
	
estimates clear	
qui reg poor215_d temp_d rainfall_sum_d humid_d ln_GDPppp_d Unempilo_d agri_d manuf_d popgr_d  if inlist(income_classification,"L","LM")
	est store low_inc
qui reg poor215_d temp_d rainfall_sum_d humid_d ln_GDPppp_d Unempilo_d agri_d manuf_d popgr_d  if inlist(income_classification,"H","UM")
	est store high_inc	
	
qui suest low_inc high_inc	
test [low_inc_mean]temp_d - [high_inc_mean]temp_d = 0

estimates clear	
qui reg gini_d temp_d rainfall_sum_d humid_d ln_GDPppp_d Unempilo_d agri_d manuf_d popgr_d  if inlist(income_classification,"L","LM")
	est store low_inc
qui reg gini_d temp_d rainfall_sum_d humid_d ln_GDPppp_d Unempilo_d agri_d manuf_d popgr_d  if inlist(income_classification,"H","UM")
	est store high_inc	
	
qui suest low_inc high_inc	
test [low_inc_mean]temp_d - [high_inc_mean]temp_d = 0
	
// T-test: FE vs LD
use "${date}/_data/spid_for_analysis_v2.dta", clear

encode geo_code2_new, gen(id_region)

	sort code year
	merge m:1 code year using "${date}/_data/income_classification.dta"
	drop if _merge==2
	drop _merge

qui reg poor215 temp rainfall_sum humid i.id_region i.year ln_GDPppp Unempilo agri manuf popgr if inlist(income_classification,"L","LM")
	est store fe_poor_lowinc
qui reg gini temp rainfall_sum humid i.id_region i.year ln_GDPppp Unempilo agri manuf popgr if inlist(income_classification,"L","LM")
	est store fe_gini_lowinc
	
qui reg poor215 temp rainfall_sum humid i.id_region i.year ln_GDPppp Unempilo agri manuf popgr if inlist(income_classification,"H","UM")
	est store fe_poor_highinc
qui reg gini temp rainfall_sum humid i.id_region i.year ln_GDPppp Unempilo agri manuf popgr if inlist(income_classification,"H","UM")
	est store fe_gini_highinc
	
bysort 	geo_code2_new (year): egen year_min = min(year)
bysort 	geo_code2_new (year): egen year_max = max(year)

keep if year == year_min | year == year_max

bysort geo_code2_new (year): gen n = _n
bysort geo_code2_new (year): gen N = _N
	keep if N==2
	
xtset id_region n
foreach v in gini theil temp poor215 poor365 poor685 rainfall_sum humid ln_GDPppp Unempilo agri manuf edupri eduter popgr tech {
	gen `v'_d = D.`v'
}
	
qui reg poor215_d temp_d rainfall_sum_d humid_d ln_GDPppp_d Unempilo_d agri_d manuf_d popgr_d  if inlist(income_classification,"L","LM")
	est store ld_poor_lowinc	
qui reg gini_d temp_d rainfall_sum_d humid_d ln_GDPppp_d Unempilo_d agri_d manuf_d popgr_d  if inlist(income_classification,"L","LM")
	est store ld_gini_lowinc	
	
qui reg poor215_d temp_d rainfall_sum_d humid_d ln_GDPppp_d Unempilo_d agri_d manuf_d popgr_d  if inlist(income_classification,"H","UM")
	est store ld_poor_highinc	
qui reg gini_d temp_d rainfall_sum_d humid_d ln_GDPppp_d Unempilo_d agri_d manuf_d popgr_d  if inlist(income_classification,"H","UM")
	est store ld_gini_highinc	
	
qui suest fe_poor_lowinc ld_poor_lowinc	
test [fe_poor_lowinc_mean]temp - [ld_poor_lowinc_mean]temp_d = 0

qui suest fe_gini_lowinc ld_gini_lowinc
test [fe_gini_lowinc_mean]temp - [ld_gini_lowinc_mean]temp_d = 0

qui suest fe_poor_highinc ld_poor_highinc	
test [fe_poor_highinc_mean]temp - [ld_poor_highinc_mean]temp_d = 0

qui suest fe_gini_highinc ld_gini_highinc
test [fe_gini_highinc_mean]temp - [ld_gini_highinc_mean]temp_d = 0

